package comparable;

import java.util.Arrays;
import java.util.Collections;
import java.util.Comparator;
import java.util.HashMap;

public class ComparableTest {

    public static void main(String[] args) {
        Student[] students = {
                new Student(9,"李博飞"),
                new Student(2,"李硕"),
                new Student(3,"333"),
                new Student(3,"111"),
                new Student(3,"222"),
                new Student(4,"李baby")
        };

//        Arrays.sort(students);
        Arrays.sort(students, Collections.<Student>reverseOrder());
        for(Student student : students){
            System.out.println(student.toString());
        }
        System.out.println(students);
        System.out.println("pack".equals(null));


        int s = Arrays.binarySearch(students, new Student(4, "李baby"), new Comparator<Student>() {
            @Override
            public int compare(Student o1, Student o2) {
                if (o1.getId() != o2.getId()) {
                    return o1.getId() < o2.getId() ? 1 : -1;
                }else{
                    if (o1.getName().equals(o2.getName())) {
                        return 0;
                    }
                    return o1.getName().compareTo(o2.getName()) > 0 ? 1 : -1;
                }
            }
        });
        if(s > -1){
            System.out.println(s);
        }

    }
}
